function transTree(arr) {
  const targetArr = []
  const map = {}
  arr.forEach(item => {
    map[item.id] = item
    map[item.id].children = []
  })
  arr.forEach(item => {
    if (map[item.pid]) {
      map[item.pid].children.push(item)
    } else {
      targetArr.push(item)
    }
  })
  return targetArr
}
export default transTree
